package com.sansecy.sunsetfigure;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import androidx.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

public class SunsetFigure extends View {
    private static final String TAG = "SunsetFigure-App";
    private int sun;
    private int moon;
    private int screenHeight;
    private int screenWidth;

    public SunsetFigure(Context context) {
        super(context);
        init();
    }

    private void init() {

    }

    public SunsetFigure(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        screenHeight = h;
        screenWidth = w;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        int baseLineX = 0;
        int baseLineY = 200;

        //画基线
        Paint paint = new Paint();
        paint.setColor(Color.RED);
        canvas.drawLine(baseLineX, baseLineY, 3000, baseLineY, paint);
        //写文字
        paint.setColor(Color.GREEN);
        paint.setTextSize(100);
        paint.setTextAlign(Paint.Align.CENTER);
        canvas.drawText("harvic\'s blog 王权富贵", baseLineX, baseLineY, paint);

        Paint.FontMetrics fontMetrics = paint.getFontMetrics();
        float ascent = baseLineY + fontMetrics.ascent;
        float descent = baseLineY + fontMetrics.descent;
        float top = baseLineY + fontMetrics.top;
        float bottom = baseLineY + fontMetrics.bottom;
        paint.setColor(Color.BLUE);
        canvas.drawLine(baseLineX, ascent, 3000, top, paint);
    }
}
